﻿using ImageDefine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ImageToolGrab
{
    [Serializable]
    public class ImageToolGrab:ImageToolBase
    {
        public ToolSetting Setting;
        public ImageToolGrab():base()
        {
            Setting=new ToolSetting();
        }
        public ImageToolGrab(ImageToolBase imageBase):base(imageBase)
        {
            Setting = new ToolSetting();
        }
        override public void CreateActioner(ImageTask imageTaskIn)
        {
            imageTask = imageTaskIn;
            OutPutResults = new Dictionary<string, string>();
            strTaskName = imageTask.Name;

        }
        override public void Run(HalconDotNet.HImage hImage, SmartDisplayControl.SmartDisplayControl smartDisplay)
        {
            FrameManager.FrameManager.Camera1.SetGainAndShutter(Setting.Gain, Setting.ExporsureMs);
            if(imageTask.currentImage!=null)
            {
                imageTask.currentImage.Dispose();
            }
            imageTask.currentImage = FrameManager.FrameManager.Camera1.GrabImage();
            if (imageTask.currentImage == null)
            {
                bResultOK = false;
                return;
            }
            smartDisplay.ShowImage(imageTask.currentImage);
            ImageToolResults = new List<ImageToolResult>();
            bResultOK = true;
        }
       
        public static ImageToolTypeInfo ToolTypeRegister()
        {
            ImageToolTypeInfo imageToolTypeInfo = new ImageToolTypeInfo();
            imageToolTypeInfo.ToolName = "相机抓图工具";
            imageToolTypeInfo.toolType = typeof(ImageToolGrab);
            return imageToolTypeInfo;
        }
        public override Form ShowSettingFrm()
        {
            FormSetting formSetting = new FormSetting(imageTask,this);
            return formSetting;
        }
    }

}
